/******************************************************************************/
package jamie.org.sil.www.usxUtils;


/******************************************************************************/
/**
   Bookmark information -- a singleton which holds details of the current
   position in the scripture we are processing.
   <p>

   This could probably all be done equally well simply by having local
   variables in the classes which need this information, but I have a
   feeling it may occasionally be useful to have some global record
   such as this one.
   <p>
 
   The constructor is public just in case you find a need for multiple
   instances, but currently that seems unlikely.
 */

public class Bookmark
{
  /****************************************************************************/
  /****************************************************************************/
  /**                                                                        **/
  /**                               Public                                   **/
  /**                                                                        **/
  /****************************************************************************/
  /****************************************************************************/

  /****************************************************************************/
  /**
     Singleton instance.

     @return Instance.
  */

  public static Bookmark instance ()
  {
    if (null == m_Instance) m_Instance = new Bookmark();
    return m_Instance;
  }


  /****************************************************************************/
  /* Constructor. */

  public Bookmark () {}


  /****************************************************************************/
  /**
     Returns an indication of whether the low verse this time round is equal
     to the high verse from last time.  This may be useful when generating
     anchors, since if you have something like 1-6a followed by 6b-10, the
     risk is otherwise that you generate an anchor for verse 6 twice.

     @return True if low verse now is the same as the high verse previously
             (and is non-zero).
  */
  
  public boolean getVerseLowEqualsPreviousVerseHigh () { return m_VerseLowEqualsPreviousVerseHigh; }


  /****************************************************************************/
  public String getUbsAbbreviatedName () { return BibleDetails.instance().getAbbreviatedUbsName(m_BookNo); }
  public BookElement getBookElement () { return BookAssembly.instance().getBookElement(getUbsAbbreviatedName()); }
  public int getBookNo () { return m_BookNo; }
  public int getChapter () { return m_Chapter; }
  public String getSubVerse () { return m_SubVerse; }
  public String getSubVerseLow () { return m_SubVerseLow; }
  public String getSubVerseHigh () { return m_SubVerseHigh; }
  public int getVerse () { return m_VerseLow; }
  public int getVerseLow () { return m_VerseLow; }
  public int getVerseHigh () { return m_VerseHigh; }

  
  public void clear () { setBookNo(""); }
  public void setBookNo (String ubsAbbrev) throws ConverterException { m_BookNo = (0 == ubsAbbrev.length() ? 0 : BibleDetails.instance().getUbsBookNumber_E(ubsAbbrev)); setChapter(0); }
  public void setChapter (int chapter) { m_Chapter = chapter; setVerse(0); }
  public void setSubVerse (String subVerse) { m_SubVerseLow = subVerse; m_SubVerseHigh = subVerse; }
  public void setSubVerseLow (String subVerseLow) { m_SubVerseLow = subVerseLow; }
  public void setSubVerseHigh (String subVerseHigh) { m_SubVerseHigh = subVerseHigh; }
  public void setVerse (int verse) { setVerseLow(verse); setVerseHigh(verse); }

  public void setVerseLow (int verseLow)
    { m_VerseLow = verseLow; m_SubVerseLow = ""; m_VerseLowEqualsPreviousVerseHigh = (0 != m_VerseLow && m_VerseLow == m_VerseHigh); }
  
  public void setVerseHigh (int verseHigh) { m_VerseHigh = verseHigh; m_SubVerseHigh = ""; }

  public void incrementChapter () { setChapter(1 + m_Chapter); }
  public void incrementVerse () { setVerse(1 + m_Verse); }
  
  public String getFullUbsName () { return BibleDetails.instance().getFullUbsName(m_BookNo); }
  public String getFullVernacularName () { return BibleDetails.instance().getFullVernacularName(m_BookNo); }





  /****************************************************************************/
  /****************************************************************************/
  /**                                                                        **/
  /**                               Private                                  **/
  /**                                                                        **/
  /****************************************************************************/
  /****************************************************************************/

  /****************************************************************************/
  private int m_BookNo = 0;
  private int m_Chapter = 0;
  private String m_SubVerse = "";
  private String m_SubVerseLow = "";
  private String m_SubVerseHigh = "";
  private int m_Verse = 0;
  private int m_VerseLow = 0;
  private int m_VerseHigh = 0;
  private static Bookmark m_Instance = null;
  private boolean m_VerseLowEqualsPreviousVerseHigh = false;
}

